package com.sinaapp.gavinzhang.GSpider.config;

import com.sinaapp.gavinzhang.GSpider.PendingWebUrlList;
import com.sinaapp.gavinzhang.GSpider.DefaultPageProcessor;
import com.sinaapp.gavinzhang.GSpider.VisitedWebUrlList;
import com.sinaapp.gavinzhang.GSpider.core.AbstractGWebUrlList;
import com.sinaapp.gavinzhang.GSpider.core.PageProcessor;
import com.sinaapp.gavinzhang.GSpider.process.DefaultHttpProcessorInterceptor;
import com.sinaapp.gavinzhang.GSpider.process.HttpProcessorInterceptor;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Created by gavin on 15-9-2.
 */
public class PageProcessorConfig {
    /** 任务网址列表*/
    private AbstractGWebUrlList pendingUrlList;
    /** 已经处理过的网址*/
    private AbstractGWebUrlList visitedUrlList;

    /** Task*/
    /** 符合要求的网址正则表达*/
    private List<Pattern> patterns;
    /** 设置处理目标函数*/
    private PageProcessor pageProcessor;

    /**网页获取拦截器
     * 以后要改用list
     * */
    private HttpProcessorInterceptor httpProcessorInterceptor;

    private int timeout = Constants.TIMEOUT;//最大重复次数
    private int sleepTime = Constants.SLEEPTIME;//如果太快初始睡眠时间
    private int waitTime = Constants.WAITTIME;//默认等待时间，现在还未启用
    private int currentListSize = Constants.CHECK_VISITEDLIST_SIZE;//需要筛选网址的待访问列表最大大小


    public static PageProcessorConfig getDefaultPageProcessorConfig()
    {
        PageProcessorConfig pageProcessorConfig = new PageProcessorConfig();
        pageProcessorConfig.pendingUrlList = new PendingWebUrlList();
        pageProcessorConfig.visitedUrlList = new VisitedWebUrlList();
        pageProcessorConfig.patterns = new ArrayList<>();
        pageProcessorConfig.pageProcessor = new DefaultPageProcessor();
        pageProcessorConfig.httpProcessorInterceptor = new DefaultHttpProcessorInterceptor();
        pageProcessorConfig.timeout = Constants.TIMEOUT;
        pageProcessorConfig.sleepTime = Constants.SLEEPTIME;
        pageProcessorConfig.waitTime = Constants.WAITTIME;
        pageProcessorConfig.currentListSize = Constants.CHECK_VISITEDLIST_SIZE;
        return pageProcessorConfig;
    }

    public HttpProcessorInterceptor getHttpProcessorInterceptor() {
        return httpProcessorInterceptor;
    }

    public void setHttpProcessorInterceptor(HttpProcessorInterceptor httpProcessorInterceptor)  {
        this.httpProcessorInterceptor = httpProcessorInterceptor;
    }

    public AbstractGWebUrlList getPendingUrlList() {
        return pendingUrlList;
    }

    public void setPendingUrlList(AbstractGWebUrlList pendingUrlList) {
        this.pendingUrlList = pendingUrlList;
    }

    public AbstractGWebUrlList getVisitedUrlList() {
        return visitedUrlList;
    }

    public void setVisitedUrlList(AbstractGWebUrlList visitedUrlList) {
        this.visitedUrlList = visitedUrlList;
    }

    public List<Pattern> getPatterns() {
        return patterns;
    }

    public void setPatterns(List<Pattern> patterns) {
        this.patterns = patterns;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public int getSleepTime() {
        return sleepTime;
    }

    public void setSleepTime(int sleepTime) {
        this.sleepTime = sleepTime;
    }

    public int getWaitTime() {
        return waitTime;
    }

    public void setWaitTime(int waitTime) {
        this.waitTime = waitTime;
    }

    public int getCurrentListSize() {
        return currentListSize;
    }

    public void setCurrentListSize(int currentListSize) {
        this.currentListSize = currentListSize;
    }


    @Deprecated
    public AbstractGWebUrlList getCurrentUrlList() {
        return pendingUrlList;
    }

    @Deprecated
    public void setCurrentUrlList(AbstractGWebUrlList currentUrlList) {
        this.pendingUrlList = currentUrlList;
    }

    @Deprecated
    public AbstractGWebUrlList getFoundUrlList() {
        return visitedUrlList;
    }

    @Deprecated
    public void setFoundUrlList(AbstractGWebUrlList foundUrlList) {
        this.visitedUrlList = foundUrlList;
    }
    /**
     * 改为pattens
     * */
    @Deprecated
    public List<Pattern> getListP() {
        return patterns;
    }

    /**
     * 改为pattens
     * */
    @Deprecated
    public void setListP(List<Pattern> listP) {
        this.patterns = listP;
    }

    public PageProcessor getPageProcessor() {
        return pageProcessor;
    }

    public void setPageProcessor(PageProcessor pageProcessor) {
        this.pageProcessor = pageProcessor;
    }

    @Deprecated
    public List<Pattern> getPatternUrls() {
        return patterns;
    }

    @Deprecated
    public void setPatternUrls(List<Pattern> patternUrls) {
        this.patterns = patternUrls;
    }
}
